#pragma once

#ifndef CONFIGHELPER_H
#define CONFIGHELPER_H

#include <QObject>
#include <QSettings>
#include <QFile>
#include <QVariant>
#include <QScopedPointer>
#include "singleton.h"

class ConfigHelper : public QObject
{
    Q_OBJECT
public:
    SINGLETON(ConfigHelper)
    // 删除拷贝构造函数和赋值运算符
    ConfigHelper(const ConfigHelper&) = delete;
    ConfigHelper& operator=(const ConfigHelper&) = delete;

    // 获取单例实例
    static ConfigHelper& instance();

    bool initialized;
    // 初始化配置文件
    bool initialize(const QString& configPath = "config.ini");

    // 通用配置读取方法
    QVariant getValue(const QString& group,
                      const QString& key,
                      const QVariant& defaultValue = QVariant()) const;

    // 类型化配置读取方法
    QString getString(const QString& group,
                      const QString& key,
                      const QString& defaultValue = "") const;

    int getInt(const QString& group,
               const QString& key,
               int defaultValue = 0) const;

    bool getBool(const QString& group,
                 const QString& key,
                 bool defaultValue = false) const;

    double getDouble(const QString& group,
                     const QString& key,
                     double defaultValue = 0.0) const;

private:
    explicit ConfigHelper(QObject* parent = nullptr);
    ~ConfigHelper() = default;

    QScopedPointer<QSettings> m_settings;
    QString m_currentConfigPath;
};

#endif // CONFIGHELPER_H
